/**
 * 对象工具类
 */

// 清空对象的属性值
export const clear = (obj) => {
    if (obj === null || typeof obj !== 'object') {
        return
    }

    for (const key in obj) {
       if (obj.hasOwnProperty(key)) {
           const value = obj[key]

           if (value !== null && Array.isArray(value)) {
               obj[key] = []
           } else {
               if (value !== null && typeof value === 'object') {
                   clear(obj[key])
               } else {
                    if (typeof value === 'string') {
                        obj[key] = '';
                    } else if (typeof value === 'number') {
                        obj[key] = ''  // 避免下拉选择回显0
                    } else if (typeof value === 'boolean') {
                        obj[key] = false
                    } else if (value instanceof Date) {
                        obj[key] = new Date(null)
                    } else {
                        obj[key] = null
                    }
               }
           }
       }
    }
}
